package Servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Dao.StudentsInformationDao;
import Dao.TeachersInformationDao;
import Entity.Student;
import Entity.Teacher;

/**
 * Servlet implementation class TeacherPersonalServlet
 */
//@WebServlet("/TeacherPersonalServlet")
public class TeacherPersonalServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TeacherPersonalServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");//解决乱码
		response.setContentType("text/html;charset=utf-8");//解决乱码
		response.setCharacterEncoding("utf-8");
		String opttype=request.getParameter("opttype");
		String teacherNo = "", teacherName, sex, dept, teacherId, pwd, tel;
		System.out.print(opttype);
		
		switch(opttype) {
		case "showMyPersonal":
			response.sendRedirect("JSP_teacherPersonalManage/myPersonalInformation_teacher.jsp");
			break;
			
		case "update":
			teacherNo = request.getParameter("teacherNo");
			teacherName = request.getParameter("teacherName");
			sex = request.getParameter("sex");
			dept = request.getParameter("dept");
			teacherId = request.getParameter("teacherId");
			pwd = request.getParameter("pwd");
			tel = request.getParameter("tel");
			Teacher teacher=new Teacher(teacherNo,teacherName,sex,dept,teacherId,pwd,tel);
			 if(new TeachersInformationDao().alterTeacherInformation(teacher)>0) {
				 response.sendRedirect("/UniversityResourceSystem/TeacherPersonalServlet?opttype=showMyPersonal"); 
			 }
			 break;
		}
	}

}
